// 引入api
import { reqcatelist } from '../../http/api'
//状态
let state = {
    //1. 初始化数据
    list: []
}

//导出状态
let getters = {
    //2. 导出list
    list(state) {
        return state.list
    }
}

//修改状态
let mutations = {
    // 3.修改list
    changeList(state,list){
        state.list=list;
    }
}

//做逻辑 做异步
let actions = {
    // ist逻辑
    reqList(context) {
        //发请求
        reqcatelist({istree:true}).then(res => {
            if (res.data.code == 200) {
                // 得到数组给list赋值
                // 必须通过commit来改
                context.commit('changeList',res.data.list?res.data.list :[])
            }
        })
    }
}

export default {
    state,
    getters,
    mutations,
    actions,
    //命名空间
    namespaced: true
}